package main

import (
	"context"
	consulService "demo/consul"
	"demo/proto/greeter"
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
)

func main() {
	//获取地址
	address, err := consulService.GetServiceAddressFromConsul("greeter")

	//连接服务器
	grpClient, err := grpc.NewClient(address, grpc.WithTransportCredentials(insecure.NewCredentials()))
	if err != nil {
		fmt.Println("连接失败", err)
	}
	defer grpClient.Close()
	//注册客户端
	client := greeter.NewGreeterClient(grpClient)
	//调用方法
	res, err := client.SayHello(context.Background(), &greeter.HelloReq{Name: "张三"})
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(res)
	fmt.Println(res.Message)
}
